/*
    数组搜索
    拓展:如果查到有重复,则打印所有索引;没查到,返回-1.
 */
import java.util.Scanner;

public class ArrSearchFor {
    public static void main(String[] args) {
        int[] arr = {11,13,11,45,34};
        int i,j = 0;
        boolean result = false;
        int[] Index = {-1,-1,-1,-1,-1};

        Scanner sc = new Scanner(System.in);
        System.out.println("请输入数字");
        int d = sc.nextInt();

        for (i = 0;i < arr.length;i++){
            if (arr[i] == d){
                //result = true;
                //break;
                Index[j++] = i;
            }
        }
//        if(result){
//            System.out.println("数组第" + (i + 1) + "个元素与输入相同");
//        }else System.out.println("数组元素与输入不同");

        //拓展
        for (int k = 0;k < Index.length;k++){
            if(Index[k] < 0){
                if(k == 0){
                    System.out.println(Index[k] + " 没有该元素");
                }
                break;
            }else System.out.print(Index[k] + " ");
        }
    }
}
